package com.test.service.impl;

import com.test.service.DefaultConfigTestService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class DefaultConfigTestServiceImpl implements DefaultConfigTestService {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    @Transactional
    public void defaultTransactionalMethod() {
        System.out.println("Default @Transactional method");
        jdbcTemplate.execute("INSERT INTO test_table (name) VALUES ('default')");
    }

    @Override
    @Transactional
    public void checkedExceptionMethod() throws Exception {
        System.out.println("Method with checked exception");
        jdbcTemplate.execute("INSERT INTO test_table (name) VALUES ('checked')");
        throw new Exception("Checked exception");
    }

    @Override
    @Transactional
    public void runtimeExceptionMethod() {
        System.out.println("Method with runtime exception");
        jdbcTemplate.execute("INSERT INTO test_table (name) VALUES ('runtime')");
        throw new RuntimeException("Runtime exception");
    }
}
